package com.codingfuture.erp_system.service.impl;

import com.codingfuture.erp_system.entity.Customer;
import com.codingfuture.erp_system.mapper.CustomerMapper;
import com.codingfuture.erp_system.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public List<Customer> findByAll() {
        return customerMapper.findByAll();
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean insertCustomer(Customer customer) {
        return customerMapper.insertCustomer(customer) != 0;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteCustomer(Integer id) {
        return customerMapper.deleteCustomer(id) != 0;
    }

    @Override
    public Customer findById(Integer id) {
        return customerMapper.findById(id);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateCustomer(Customer customer) {
        return customerMapper.updateCustomer(customer) != 0;
    }

    @Override
    public List<Customer> findByAll(Customer customer) {
        return customerMapper.findByAll(customer);
    }

    @Override
    public Customer findByName(String name) {
        return customerMapper.findByName(name);
    }
}
